package com.tanhua.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.common.mapper.BlackListMapper;
import com.tanhua.common.pojo.BlackList;
import com.tanhua.server.service.BlackListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;
    @Override
    public IPage<BlackList> queryBlackList(Long userId, Integer page, Integer pageSize) {

        QueryWrapper<BlackList> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.orderByDesc("created");
        Page<BlackList> pager=new Page<>(page,pageSize);
        IPage<BlackList> blackListIPage = this.blackListMapper.selectPage(pager, queryWrapper);

        return blackListIPage ;
    }

    @Override
    public boolean delBlackList(Long userId, Long blackUserId) {
        QueryWrapper<BlackList> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId).eq("black_user_id",blackUserId);
        return this.blackListMapper.delete(wrapper)>0;
    }
}
